package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.inn.DishesInfo;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class DishesDaoImpl extends TempDao {
    public Map<Integer, DishesInfo> getDishesInfoMap() {
        Map<Integer, DishesInfo> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_inn_dishes";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                DishesInfo dishesInfo = new DishesInfo();

                dishesInfo.setDishesId(rs.getInt("id"));
                dishesInfo.setDishesType(rs.getInt("type"));
                dishesInfo.setConsume(rs.getString("consume"));
                dishesInfo.setCookSecond(rs.getInt("time"));
                dishesInfo.setRewords(rs.getString("rewards"));
                dishesInfo.setMoneyPerSnd(rs.getLong("moneyPerSnd"));
                dishesInfo.setSkillId(rs.getInt("skillId"));
                dishesInfo.setQuality(rs.getInt("quality"));
                dataMap.put(dishesInfo.getDishesId(),dishesInfo);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
